import {ServicePrefixEnum} from "@/enums/commonEnum";
import {RequestEnum} from "@/enums/httpEnum";
import type {AxiosRequestConfig} from "axios";
import {defHttp} from "@/utils/http/axios";

export interface PermissionAssignUserRoleReqVO {
  userId: number
  roleIds: number[]
}

export interface PermissionAssignRoleMenuReqVO {
  roleId: number
  menuIds: number[]
}

export interface PermissionAssignRoleDataScopeReqVO {
  roleId: number
  dataScope: number
  dataScopeDeptIds: number[]
}

const MODULAR = '/system/permission';

export const Api ={
  GetRoleMenuList:{
    url: `${ServicePrefixEnum.BASE}/${MODULAR}/list-role-menus`,
    method: RequestEnum.GET,
  } as AxiosRequestConfig,
  AssignRoleMenu:{
    url: `${ServicePrefixEnum.BASE}/${MODULAR}/assign-role-menu`,
    method: RequestEnum.POST,
  } as AxiosRequestConfig,
  AssignRoleDataScope:{
    url: `${ServicePrefixEnum.BASE}/${MODULAR}/assign-role-data-scope`,
    method: RequestEnum.POST,
  } as AxiosRequestConfig,
  GetUserRoleList:{
    url: `${ServicePrefixEnum.BASE}/${MODULAR}/list-user-roles`,
    method: RequestEnum.GET,
  } as AxiosRequestConfig,
  AssignUserRole:{
    url: `${ServicePrefixEnum.BASE}/${MODULAR}/assign-user-role`,
    method: RequestEnum.POST,
  } as AxiosRequestConfig

}

// 查询角色拥有的菜单权限
export const getRoleMenuList = (roleId) => {
  let params = {roleId:roleId}
  return defHttp.request({ ...Api.GetRoleMenuList,params})
}

// 赋予角色菜单权限
export const assignRoleMenu = (data) => {
  return defHttp.request({ ...Api.AssignRoleMenu,params:data})
}

// 赋予角色数据权限
export const assignRoleDataScope = (data) => {
  return defHttp.request({ ...Api.AssignRoleDataScope,params:data})
}

// 查询用户拥有的角色数组
export const getUserRoleList = (userId) => {
  let params = {userId:userId}
  return defHttp.request({ ...Api.GetUserRoleList,params})
}

// 赋予用户角色
export const assignUserRole = (data) => {
  return defHttp.request({ ...Api.AssignUserRole,params:data})
}